package com.ccys.cms.service.userManagement.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ccys.cms.service.userManagement.*;
import com.ccys.common.util.Kit;
import com.ccys.common.util.PBKDF2Util;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.userManagement.DoctorAppointmentSettingDto;
import com.ccys.db.dto.userManagement.DoctorDto;
import com.ccys.db.entity.*;
import com.ccys.db.mapper.*;
import com.ccys.db.page.PageDto;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.service.BaseTblAuditTrailWebService;
import com.ccys.db.vo.userManagement.*;
import com.github.pagehelper.PageInfo;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @program: WhiteCoat
 * @description: 医生接口实现类
 * @author: ZhangJingCan
 * @create: 2023-12-18 16:36
 **/

@Service
public class DoctorServiceImpl extends BaseServiceImpl<TblDoctor> implements DoctorService {

    /**
     * 医生
     */
    @Resource
    private TblDoctorMapper tblDoctorMapper;

    /**
     * 医生语言
     */
    @Resource
    private TblDoctorSpeakLanguageMapper tblDoctorSpeakLanguageMapper;

    @Autowired(required = false)
    private DoctorSpeakLanguageService doctorSpeakLanguageService;

    /**
     * 医生的获奖
     */
    @Resource
    private TblDoctorAwardsMapper tblDoctorAwardsMapper;

    @Autowired(required = false)
    private DoctorAwardsService doctorAwardsService;

    /**
     * 医生的教育经历
     */
    @Resource
    private TblDoctorEducationMapper tblDoctorEducationMapper;

    @Autowired(required = false)
    private DoctorEducationService doctorEducationService;

    /**
     * 医生的证书
     */
    @Resource
    private TblDoctorCertificationsMapper tblDoctorCertificationsMapper;

    @Autowired(required = false)
    private DoctorCertificationsService doctorCertificationsService;

    /**
     * 医生可以在哪些诊所
     */
    @Resource
    private TblDoctorClinicMapper tblDoctorClinicMapper;

    @Autowired(required = false)
    private DoctorClinicService doctorClinicService;

    /**
     * SP 医生设置 display 的问诊费用展示
     */
    @Resource
    private TblDoctorConsultFeeAppMapper tblDoctorConsultFeeAppMapper;

    @Autowired(required = false)
    private DoctorConsultFeeAppService doctorConsultFeeAppService;

    /**
     * SP 医生 dropDown 的价格设置
     */
    @Resource
    private TblDoctorConsultFeeMapper tblDoctorConsultFeeMapper;

    /**
     * SP医生选择专科
     */
    @Resource
    private TblDoctorSpecialisationMapper tblDoctorSpecialisationMapper;

    @Autowired(required = false)
    private DoctorSpecialisationService doctorSpecialisationService;

    /**
     * 医生排班表
     */
    @Resource
    private TblDoctorAppointmentSettingMapper tblDoctorAppointmentSettingMapper;

    /**
     * 用于保存修改状态日志
     */
    @Autowired(required = false)
    private BaseTblAuditTrailWebService baseTblAuditTrailWebService;

    /**
     * 处方主表
     */
    @Resource
    private TblFavouritePrescriptionMapper tblFavouritePrescriptionMapper;

    /**
     * 病人标签关联表
     */
    @Resource
    private TblFlagMemberMapper tblFlagMemberMapper;

    @Resource
    private TblDoctorYearOfPracticeMapper tblDoctorYearOfPracticeMapper;

    /**
     * SP 医生 dropDown 的价格设置
     */
    @Autowired
    private DoctorConsultFeeService doctorConsultFeeService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult saveDoctor(DoctorDto dto) throws ParseException {
        if(dto.getPanelType() == null) {
            return ResponseResult.error("illegal request!");
        }
        //先判断是GP-全科医生还是SP-专科医生
        if (2 == dto.getPanelType()) {
            //全科医生-GP
            Kit.allParamValid(dto, "companyId", "fullAccess", "jobType","utiliseWcappt", "firstName", "email", "password"
                    , "address" , "specialisations", "countryOfResidence",  "doctorType", "gender", "dob", "consultPatientFrom");
            if (ObjectUtil.isEmpty(dto.getId())) {
                //加密密码
                Integer iterationPassword = PBKDF2Util.generateIterationPassword();
                String saltPassword = PBKDF2Util.generateSaltPassword();
                String hash = PBKDF2Util.createHashPassword(dto.getPassword(),iterationPassword,saltPassword);
                //设置盐和迭代次数
                dto.setIterationPassword(iterationPassword);
                dto.setSaltPassword(saltPassword);
                //设置加密之后的密码
                dto.setPassword(hash);
                //新增
                tblDoctorMapper.insertSelective(dto);
                //调用公共方法新增
                addByPanelType(dto);
                return ResponseResult.success("Successfully added a general practitioner!");
            } else {
                TblDoctor tblDoctor = tblDoctorMapper.selectByPrimaryKey(dto.getId());
                //密码字段不为空 - 并且和数据库对比不相等
                if (ObjectUtil.isNotEmpty(dto.getPassword()) && !tblDoctor.getPassword().equals(dto.getPassword())){
                    //如果密码不相等 - 就重新加密
                    String hash = PBKDF2Util.createHashPassword(dto.getPassword(),tblDoctor.getIterationPassword(),tblDoctor.getSaltPassword());
                    dto.setPassword(hash);
                }
                tblDoctorMapper.updateByPrimaryKeySelective(dto);
                //修改 - 先删除所有关联的表数据
                deleteByPanelType(dto.getPanelType(), dto.getId());
                //删除之后 - 调用公共方法新增
                addByPanelType(dto);
                return ResponseResult.success("Successfully modified the general practitioner!");
            }

        } else if (1 == dto.getPanelType()) {
            //专科医生
            Kit.allParamValid(dto, "companyId",  "fullAccess", "firstName", "jobType", "lastName"
                    , "email", "password", "address", "countryOfResidence"
                    , "doctorType", "gender", "dob", "consultPatientFrom");
            if (ObjectUtil.isEmpty(dto.getId())) {
                //加密密码
                Integer iterationPassword = PBKDF2Util.generateIterationPassword();
                String saltPassword = PBKDF2Util.generateSaltPassword();
                String hash = PBKDF2Util.createHashPassword(dto.getPassword(),iterationPassword,saltPassword);
                //设置盐和迭代次数
                dto.setIterationPassword(iterationPassword);
                dto.setSaltPassword(saltPassword);
                //设置加密之后的密码
                dto.setPassword(hash);
                //新增
                tblDoctorMapper.insertSelective(dto);
                //调用公共方法新增
                addByPanelType(dto);
                return ResponseResult.success("Successfully added specialist doctor!");
            } else {
                TblDoctor tblDoctor = tblDoctorMapper.selectByPrimaryKey(dto.getId());
                //密码字段不为空 - 并且和数据库对比不相等
                if (ObjectUtil.isNotEmpty(dto.getPassword()) && !tblDoctor.getPassword().equals(dto.getPassword())){
                    //如果密码不相等 - 就重新加密
                    String hash = PBKDF2Util.createHashPassword(dto.getPassword(),tblDoctor.getIterationPassword(),tblDoctor.getSaltPassword());
                    dto.setPassword(hash);
                }
                //修改本表
                tblDoctorMapper.updateByPrimaryKeySelective(dto);
                //修改 - 先删除所有关联的表数据
                deleteByPanelType(dto.getPanelType(), dto.getId());
                //调用公共方法新增
                addByPanelType(dto);
                if (dto.getStatus() != null ) {
                    //保存修改日志
                    baseTblAuditTrailWebService.saveStatusLog(dto, dto.getStatus());
                }
                return ResponseResult.success("Successfully modified specialist doctor!");
            }
        } else {
            return ResponseResult.error("illegal request!");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult updateDoctorStatus(DoctorDto dto) {
        //校验
        if (ObjectUtil.isEmpty(dto.getId()) || ObjectUtil.isEmpty(dto.getStatus())) {
            return ResponseResult.error("Parameter Error!");
        }
        //准备数据修改
        TblDoctor tblDoctor = new TblDoctor();
        tblDoctor.setId(dto.getId());
        tblDoctor.setStatus(dto.getStatus());
        if (tblDoctorMapper.updateByPrimaryKeySelective(tblDoctor) > 0) {
            //保存修改日志
            baseTblAuditTrailWebService.saveStatusLog(dto, dto.getStatus());
            return ResponseResult.success("Modified successfully!");
        }
        return ResponseResult.error("Modification failed!");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult deleteDoctor(DoctorDto dto) {
        //判断
        if (ObjectUtil.isEmpty(dto.getId())) {
            return ResponseResult.error("Parameter Error!");
        }
        //准备实体类并赋值
        TblDoctor tblDoctor = new TblDoctor();
        tblDoctor.setId(dto.getId());
        tblDoctor.setDelFlag(1);
        //判断是否修改成功 - 返回不同状态
        if (tblDoctorMapper.updateByPrimaryKeySelective(tblDoctor) > 0) {
            return ResponseResult.success("Delete Successful!");
        }
        return ResponseResult.error("Delete Failed!");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult updateDoctorLoginStatus(DoctorDto dto) {
        //校验
        if (ObjectUtil.isEmpty(dto.getId()) || ObjectUtil.isEmpty(dto.getLoginStatus())) {
            return ResponseResult.error("Parameter Error!");
        }
        //准备数据修改
        TblDoctor tblDoctor = new TblDoctor();
        tblDoctor.setId(dto.getId());
        tblDoctor.setLoginStatus(dto.getLoginStatus());
        if (tblDoctorMapper.updateByPrimaryKeySelective(tblDoctor) > 0) {
            return ResponseResult.success("Modified successfully!");
        }
        return ResponseResult.error("Modification failed!");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult updateDoctorDispOrder(DoctorDto dto) {
        //校验
        if (ObjectUtil.isEmpty(dto.getId()) || ObjectUtil.isEmpty(dto.getDispOrder())) {
            return ResponseResult.error("Parameter Error!");
        }
        //准备数据修改
        TblDoctor tblDoctor = new TblDoctor();
        tblDoctor.setId(dto.getId());
        tblDoctor.setDispOrder(dto.getDispOrder());
        if (tblDoctorMapper.updateByPrimaryKeySelective(tblDoctor) > 0) {
            return ResponseResult.success("Modified successfully!");
        }
        return ResponseResult.error("Modification failed!");
    }

    @Override
    public ResponseResult<PageInfo<DoctorPageQueryVo>, Object> findPageDoctor(DoctorDto dto) {
        dto.setPanelType(Optional.ofNullable(dto.getPanelType()).filter(p -> p > 0 && p < 3).orElse(null));
        //开启分页
        PageDto.startPage();
        List<DoctorPageQueryVo> list = tblDoctorMapper.findPageDoctor(dto);
        PageInfo<DoctorPageQueryVo> info = new PageInfo<>(list);
        return ResponseResult.success(info);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult saveDoctorRosterSetting(DoctorDto dto) {
        //校验字段值
        Kit.allParamValid(dto, "id", "minBlockBookable", "minBlockBookableUnit", "maxBlockBookable", "maxBlockBookableUnit"
                , "blockIntervalMinute", "bufferPeriodMinute", "eapBlockIntervalMinute", "eapBufferPeriodMinute", "workOnHoliday");
        //修改医生数据
        if (tblDoctorMapper.updateByPrimaryKeySelective(dto) > 0) {
            return ResponseResult.success("Successfully saved Roster settings!");
        }
        return ResponseResult.error("Failed to save Roster settings!");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult saveDoctorSchedule(DoctorAppointmentSettingDto dto) {
        //先做公共字段校验
        Kit.allParamValid(dto, "clinicId", "shiftType", "startTime", "endTime", "doctorId");
        //判断属于什么类型，做不同校验
        if (1 == dto.getShiftType()) {
            //work
            Kit.allParamValid(dto, "repeatType", "forOnlineConsult", "forWalkinConsult", "forOnlineAppointment"
                    , "forWalkinAppointment", "forEapAppointment", "forEapWalkinAppointment", "forTextBasedAppointment");
            if (dto.getRepeatType() > 0) {
                if (ObjectUtil.isEmpty(dto.getRepeatEndTime())) {
                    return ResponseResult.error("Parameter abnormality!");
                }
            }
        } else {
            //leave
            if (ObjectUtil.isEmpty(dto.getLeaveAllDay())) {
                return ResponseResult.error("Parameter abnormality!");
            }
        }
        //判断是新增还是修改
        if (ObjectUtil.isEmpty(dto.getId())) {
            //新增设置状态为：1 - 发布 - 默认为发布
            dto.setStatus(1);
            if (tblDoctorAppointmentSettingMapper.insertSelective(dto) > 0) {
                return ResponseResult.success("Added successfully");
            }
            return ResponseResult.error("Add failed");
        } else {
            if (tblDoctorAppointmentSettingMapper.updateByPrimaryKeySelective(dto) > 0) {
                return ResponseResult.success("Modified successfully");
            }
            return ResponseResult.error("Modification failed");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult deleteDoctorSchedule(DoctorAppointmentSettingDto dto) {
        //校验
        Kit.allParamValid(dto, "id", "deleteType");
        if (ObjectUtil.isEmpty(tblDoctorAppointmentSettingMapper.selectByPrimaryKey(dto.getId()))) {
            return ResponseResult.error("data error!");
        }

        //判断属于什么类型删除 - 0-今天，1-今天和以后，2删除所有
        //如果在有repeat排班中删除某一天，则添加一条数据设置parent_id等于当前排班，开始结束时间为被删除当天的开始结束时间；如果删除当天以后的排班，则设置repeat_end_time为当天
        if (0 == dto.getDeleteType()) {
            //删除当天需要校验是否传入当天的开始时间和结束时间
            Kit.allParamValid(dto, "startTime", "endTime");
            //删除今天 - 先查询当前选中的排班数据
            TblDoctorAppointmentSetting setting = new TblDoctorAppointmentSetting();
            setting.setParentSettingId(dto.getId());
            setting.setStartTime(dto.getStartTime());
            setting.setEndTime(dto.getEndTime());
            setting.setStatus(-1);
            //新增数据并判断
            if (tblDoctorAppointmentSettingMapper.insertSelective(setting) > 0) {
                return ResponseResult.success("Operation successful!");
            } else {
                return ResponseResult.error("operation failed!");
            }
        } else if (1 == dto.getDeleteType()) {
            //删除今天以及之后所有 - 需要校验是否传入 - 当天时间减去一天的时间值
            if (ObjectUtil.isEmpty(dto.getRepeatEndTime())) {
                return ResponseResult.error("parameter error!");
            }
            //删除今天和以后 - 则设置repeat_end_time为当天
            TblDoctorAppointmentSetting setting = new TblDoctorAppointmentSetting();
            setting.setId(dto.getId());
            //设置选择的当天的前一天时间为结束时间
            setting.setRepeatEndTime(dto.getRepeatEndTime());
            if (tblDoctorAppointmentSettingMapper.updateByPrimaryKeySelective(setting) > 0) {
                return ResponseResult.success("Operation successful!");
            } else {
                return ResponseResult.error("operation failed!");
            }
        } else if (2 == dto.getDeleteType()) {
            //删除所有 - 软删除 - 将主数据删除就行
            TblDoctorAppointmentSetting setting = new TblDoctorAppointmentSetting();
            setting.setId(dto.getId());
            setting.setStatus(-1);
            setting.setDelFlag(1);
            //操作数据库软删除并返回状态
            if (tblDoctorAppointmentSettingMapper.updateByPrimaryKeySelective(setting) > 0) {
                return ResponseResult.success("Operation successful!");
            } else {
                return ResponseResult.error("operation failed!");
            }
        } else {
            return ResponseResult.error("Illegal request!");
        }
    }

    @Override
    public ResponseResult<List<DoctorAppointmentSettingFindListVo>, Object> findListDoctorSchedule(DoctorDto dto) {
        List<DoctorAppointmentSettingFindListVo> list = tblDoctorMapper.findListDoctorSchedule(dto);
        return ResponseResult.success(list);
    }

    @Override
    public ResponseResult<List<TblDoctorConsultFee>, Object> findListDoctorConsultFee(TblDoctorConsultFee dto) {
        if (ObjectUtil.isEmpty(dto.getDoctorId())) {
            return ResponseResult.error("Parameter abnormality");
        }
        Example example = new Example(TblDoctorConsultFee.class);
        example.createCriteria()
                .andEqualTo("doctorId", dto.getDoctorId())
                .andEqualTo("status", 1)
                .andEqualTo("delFlag", 0);
        return ResponseResult.success(tblDoctorConsultFeeMapper.selectByExample(example));
    }

    @Override
    public ResponseResult<DoctorDetailsVo, Object> findDoctorDetailsByDoctorId(DoctorDto dto) {
        if (ObjectUtil.isEmpty(dto.getId())) {
            return ResponseResult.error("Parameter abnormality");
        }
        DoctorDetailsVo vo = tblDoctorMapper.findDoctorDetailsByDoctorId(dto.getId());
        return ResponseResult.success(vo);
    }

    @Override
    public ResponseResult<PageInfo<DoctorInfoFavouritePrescriptionPageVo>, Object> findDoctorInfoFavouritePrescription(DoctorDto dto) {
        if (ObjectUtil.isEmpty(dto.getId())){
            return ResponseResult.error("Parameter abnormality");
        }
        PageDto.startPage();
        List<DoctorInfoFavouritePrescriptionPageVo> list = tblFavouritePrescriptionMapper.findDoctorInfoFavouritePrescription(dto.getId());
        PageInfo<DoctorInfoFavouritePrescriptionPageVo> info = new PageInfo<>(list);
        return ResponseResult.success(info);
    }

    @Override
    public ResponseResult<List<DoctorInfoFlagPatientVo>, Object> findDoctorInfoFlagPatient(DoctorDto dto) {
        //校验必传的医生id
        if (ObjectUtil.isEmpty(dto.getId())){
            return ResponseResult.error("Parameter abnormality");
        }
        List<DoctorInfoFlagPatientVo> vos = tblFlagMemberMapper.findDoctorInfoFlagPatient(dto);
        return ResponseResult.success(vos);
    }

    @Override
    public ResponseResult listSelect(DoctorDto dto) {
        PageDto.startPage();
        List<DoctorSelectWebVO> list = this.tblDoctorMapper.listSelect(dto);
        PageInfo<DoctorSelectWebVO> info = new PageInfo<>(list);
        return ResponseResult.success(info);
    }

    @Override
    public ResponseResult<List<DoctorYearOfPracticeListVo>, Object> doctorYearOfPractice() {
        return ResponseResult.success(tblDoctorYearOfPracticeMapper.findList());
    }

    @Override
    public ResponseResult<List<DoctorFindListSelectVo>, Object> findListByCountryId(DoctorDto dto) {
        List<DoctorFindListSelectVo> list = tblDoctorMapper.findListByCountryId(dto);
        return ResponseResult.success(list);
    }

    @NotNull
    @Override
    public String getCode() {
        String code = Kit.getCodeStr();
        List<String> whereList = new ArrayList<>();
        whereList.clear();
        whereList.add("del_flag=0");
        whereList.add("doctor_no= '" + code + "'");
        TblDoctor oneByLimit = this.findOneByLimit(TblDoctor.class, whereList);
        if (oneByLimit != null) {
            code = getCode();
        }
        return code;
    }


    /**
     * 公共方法 - 根据不同医生 - 生成不同的表数据
     *
     * @param dto 传入医生数据
     */
    @Transactional(rollbackFor = Exception.class)
    public void addByPanelType(DoctorDto dto) throws ParseException {
        //判断医生语言 - 不为空则新增数据
        if (ObjectUtil.isNotEmpty(dto.getLanguages())) {
            List<TblDoctorSpeakLanguage> languages = new ArrayList<>();
            String[] split = dto.getLanguages().split(",");
            for (String s : split) {
                TblDoctorSpeakLanguage language = new TblDoctorSpeakLanguage();
                language.setLanguageId(s);
                language.setDoctorId(dto.getId());
                language.preInsert();
                languages.add(language);
            }
            doctorSpeakLanguageService.insertAll(languages);
        }
        //医生的获奖
        if (ObjectUtil.isNotEmpty(dto.getAwards())) {
            List<TblDoctorAwards> awards = dto.getAwards();
            for (TblDoctorAwards award : awards) {
                award.setDoctorId(dto.getId());
                award.preInsert();
            }
            doctorAwardsService.insertAll(awards);
        }
        //医生的教育经历
        if (ObjectUtil.isNotEmpty(dto.getEducations())) {
            List<TblDoctorEducation> educations = dto.getEducations();
            for (TblDoctorEducation education : educations) {
                education.setDoctorId(dto.getId());
                education.preInsert();
            }
            doctorEducationService.insertAll(educations);
        }
        //医生的证书
        if (ObjectUtil.isNotEmpty(dto.getCertifications())) {
            List<TblDoctorCertifications> certifications = dto.getCertifications();
            for (TblDoctorCertifications certification : certifications) {
                certification.setDoctorId(dto.getId());
                certification.preInsert();
            }
            doctorCertificationsService.insertAll(certifications);
        }
        //医生可以在哪些诊所
        if (ObjectUtil.isNotEmpty(dto.getClinics())) {
            String[] split = dto.getClinics().split(",");
            List<TblDoctorClinic> clinics = new ArrayList<>();
            for (String s : split) {
                TblDoctorClinic clinic = new TblDoctorClinic();
                clinic.setDoctorId(dto.getId());
                clinic.setClinicId(s);
                clinic.preInsert();
                clinics.add(clinic);
            }
            doctorClinicService.insertAll(clinics);
        }


        if (1 == dto.getPanelType()) {
            //专科需要另外多新增一个表
            //SP 医生设置 display 的问诊费用展示
            if (ObjectUtil.isNotEmpty(dto.getConsultFeeApps())) {
                List<TblDoctorConsultFeeApp> consultFeeApps = dto.getConsultFeeApps();
                for (TblDoctorConsultFeeApp app : consultFeeApps) {
                    app.setDoctorId(dto.getId());
                    app.preInsert();
                }
                doctorConsultFeeAppService.insertAll(consultFeeApps);
            }

            //SP 医生 dropDown 的价格设置
            //专科的修改不能在这里删除TblDoctorConsultFee - 这里检查TblDoctorConsultFee是新增还是修改做相应的处理 - TblDoctorConsultFee的删除另外单独提供接口
            if (ObjectUtil.isNotEmpty(dto.getConsultFees())) {
                List<TblDoctorConsultFee> consultFees = dto.getConsultFees();
                for (TblDoctorConsultFee fee : consultFees) {
                    //校验是新增还是修改
//                    if (ObjectUtil.isEmpty(fee.getId())) {
//                        //新增 - 设置医生ID
//                        fee.setDoctorId(dto.getId());
//                        tblDoctorConsultFeeMapper.insertSelective(fee);
//                    } else {
//                        //修改
//                        tblDoctorConsultFeeMapper.updateByPrimaryKeySelective(fee);
//                    }
                    fee.setDoctorId(dto.getId());
                    fee.preInsert();
                }
                doctorConsultFeeService.insertAll(consultFees);
            }

            //SP 医生 选择专科
            if (ObjectUtil.isNotEmpty(dto.getSpecialisations())) {
                List<TblDoctorSpecialisation> specialisations = new ArrayList<>();
                for (String s : dto.getSpecialisations().split(",")) {
                    TblDoctorSpecialisation specialisation = new TblDoctorSpecialisation();
                    specialisation.setDoctorId(dto.getId());
                    specialisation.setSpecialisationId(s);
                    specialisation.preInsert();
                    specialisations.add(specialisation);
                }
                doctorSpecialisationService.insertAll(specialisations);
            }

        }
    }

    /**
     * 公共方法 - 用于医生修改时的删除关联表数据操作
     *
     * @param panelType 医生类型 - 根据不同类型删除不同的表数据
     * @param doctorId  医生ID
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteByPanelType(Integer panelType, String doctorId) {
        //全科和专科都需要删除这些表
        //删除医生关联的语言表数据
        tblDoctorSpeakLanguageMapper.deleteByDoctorId(doctorId);
        //删除医生的获奖
        tblDoctorAwardsMapper.deleteByDoctorId(doctorId);
        //删除医生的教育经历
        tblDoctorEducationMapper.deleteByDoctorId(doctorId);
        //删除医生的证书
        tblDoctorCertificationsMapper.deleteByDoctorId(doctorId);
        //删除医生可以在哪些诊所
        tblDoctorClinicMapper.deleteByDoctorId(doctorId);
        if (1 == panelType) {
            //专科需要删除更多的表数据
            //SP 医生设置 display 的问诊费用展示
            tblDoctorConsultFeeAppMapper.deleteByDoctorId(doctorId);
            //SP 医生的专科 专业关联表
            tblDoctorSpecialisationMapper.deleteByDoctorId(doctorId);
            //SP 医生 dropDown 的价格设置
            tblDoctorConsultFeeMapper.deleteByDoctorId(doctorId);
        }
    }

}
